package com.ek.common;

import java.net.SocketAddress;

import com.ek.kademlia.protocol.Message;

public abstract class AbstractMessageHandler<T extends Message> implements MessageHandler<T> {
    private final Context context;

    public AbstractMessageHandler(Context context) {
        this.context = context;
    }

    @SuppressWarnings("unchecked")
    public void execute(Object message, SocketAddress address) {
        T m = (T) message;
        doExecute(m, address);
    }

    public Context getContext() {
        return context;
    }

    protected abstract void doExecute(T message, SocketAddress address);

}
